package com.meihua.shellapp.adapter.personalcenter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.meihua.shellapp.R;
import com.meihua.shellapp.databean.PolicyDataBean;

import java.util.List;

public abstract class PolicyFragmentAdapter extends RecyclerView.Adapter<PolicyFragmentAdapter.PolicyHandler> {

    private List<PolicyDataBean> data;

    public PolicyFragmentAdapter(Context context, List<PolicyDataBean> data) {
        this.data = data;
    }

    @Override
    public PolicyHandler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_policymanage, null);
        // 实例化viewholder
        PolicyHandler viewHolder = new PolicyHandler(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(PolicyHandler holder, final int position) {
        holder.tv_name.setText("产品名称：" + data.get(position).getProduct_name());
        holder.tv_number.setText("保单号：" + data.get(position).getPolicy_number());
        holder.tv_salesman.setText("业务员：" + data.get(position).getSalesman_name());
        holder.tv_policy_holder.setText("投保人：" + data.get(position).getPolicy_holder_name());
        holder.tv_time.setText("投保时间：" + data.get(position).getInsured_date());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                click(data.get(position));
            }
        });
    }

    public abstract void click(PolicyDataBean data);

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }


    public class PolicyHandler extends RecyclerView.ViewHolder {

        TextView tv_name, tv_number, tv_salesman, tv_policy_holder, tv_time;

        public PolicyHandler(View itemView) {
            super(itemView);
            tv_name = itemView.findViewById(R.id.tv_name);
            tv_number = itemView.findViewById(R.id.tv_number);
            tv_salesman = itemView.findViewById(R.id.tv_salesman);
            tv_policy_holder = itemView.findViewById(R.id.tv_policy_holder);
            tv_time = itemView.findViewById(R.id.tv_time);
        }
    }
}